package com.zjm.behavioral.command;

/**
 * 命令模式演示
 */
public class Client {
    public static void main(String[] args) {
        // 创建电灯对象（接收者）
        LightReceiver lightReceiver = new LightReceiver();

        // 创建电灯相关的开关命令
        LightOnCommand lightOnCommand = new LightOnCommand(lightReceiver);
        LightOffCommand lightOffCommand = new LightOffCommand(lightReceiver);

        // 创建遥控器
        RemoteController remoteController = new RemoteController();

        // 给遥控器设置命令
        remoteController.setCommand(0, lightOnCommand, lightOffCommand);

        System.out.println("-------按下灯的开按钮-----------");
        remoteController.onButtonWasPushed(0);
        System.out.println("-------按下灯的关按钮-----------");
        remoteController.offButtonWasPushed(0);
        System.out.println("-------按下灯的撤销按钮-----------");
        remoteController.undoButtonWasPushed();

        System.out.println("========遥控器操作电视");

        // 创建电灯对象（接收者）
        TVReceiver tvReceiver = new TVReceiver();

        // 创建电灯相关的开关命令
        TVOnCommand tvOnCommand = new TVOnCommand(tvReceiver);
        TVOffCommand tvOffCommand = new TVOffCommand(tvReceiver);

        // 给遥控器设置命令
        remoteController.setCommand(1, tvOnCommand, tvOffCommand);

        System.out.println("-------按下电视的开按钮-----------");
        remoteController.onButtonWasPushed(1);
        System.out.println("-------按下电视的关按钮-----------");
        remoteController.offButtonWasPushed(1);
        System.out.println("-------按下电视的撤销按钮-----------");
        remoteController.undoButtonWasPushed();

    }
}
